package com.bjpowernode.common.client;

import com.bjpowernode.mvc.config.RealnameConfig;
import lombok.RequiredArgsConstructor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@RequiredArgsConstructor
@Component
public class RealnameUtil {

    /**
     * 第三方接口方法实现实名认证   杭州屹蓝公司
     *
     * @param name
     * @param idCard
     * @return
     */


    private final RealnameConfig realnameConfig;

    public String execRealnameApi(String name, String idCard) {
        String host = realnameConfig.getHost();
        String path = realnameConfig.getPath();
        String method = "POST";
        String appcode = realnameConfig.getAppCode();
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("name", name);
        bodys.put("idcard", idCard);

        String body = "{\n" +
                "    \"msg\": \"成功\",\n" +
                "    \"success\": true,\n" +
                "    \"code\": 200,\n" +
                "    \"data\": {\n" +
                "        \"birthday\": \"20020810\",\n" +
                "        \"result\": 0, \n" +
                "        \"address\": \"浙江省*******绍兴市\",\n" +
                "        \"orderNo\": \"202304021731265602998\",\n" +
                "        \"sex\": \"男\",\n" +
                "        \"desc\": \"一致\"\n" +
                "    }\n" +
                "}";

        //String body = "";
        try {
/*            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            //HttpStatus.SC_OK = 200
            System.out.println(response.getStatusLine().getStatusCode());
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                //获取response的body
                body = EntityUtils.toString(response.getEntity());
            }*/
        } catch (Exception e) {
            e.printStackTrace();
        }
        return body;
    }
}
